package org.sny7.openOfflineList.util;

import java.io.UnsupportedEncodingException;
import java.net.URL;
import java.net.URLDecoder;

public class PathGetter {

	private static final String path = initPath();

	private PathGetter() {

	}
	
	public static String getPath() {
		return path;
	}

	private static String initPath() {
		URL url = PathGetter.class.getProtectionDomain().getCodeSource()
				.getLocation();
		try {
			String path = URLDecoder.decode(url.getPath(), "UTF-8");
			if (path.contains(".jar")) {
				path = path.replaceFirst("[^/]+\\.jar.*", "").replace("file:", "");
			}
			return path;
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		}
		return "";
	}

}
